import json
from django.http import HttpResponse, JsonResponse
from Contacts.models import Contacts
def add(request):
    if request.method == "POST":
        arr = json.loads(request.body)["list"]
        for each in arr:
            if len(Contacts.objects.filter(number=each["number"])) == 0:
                Contacts.objects.create(
                    number=each["number"],
                    name=each["name"]
                ).save()
    return HttpResponse("反馈成功")

def get(request):
    contact = Contacts.objects.all()
    return JsonResponse({"data": [{
        'number': each.number,
        'name': each.name
    } for each in contact]
    })